import { extend, localize } from 'vee-validate'
import { required, email, min, max, confirmed } from 'vee-validate/dist/rules'
import zh from 'vee-validate/dist/locale/zh_CN.json'
const rules = { required, email, min, max, confirmed }

Object.keys(rules).forEach(rule => {
  extend(rule, {
    ...rules[rule]
  })
})

extend('same', {
  validate: function (value, _a) {
    const target = _a.target
    return String(value) === String(target)
  },
  params: [
    {
      name: 'target',
      isTarget: true
    }
  ],
  message: '两次密码不一致'
})

localize('zh_CN', {
  names: {
    username: '用户名',
    password: '密码',
    code: '验证码'
    // email: '邮箱'
  },
  messages: {
    ...zh.messages,
    required: '请输入{_field_}',
    min: '{_field_}不符合最小长度要求:{length}',
    max: '{_field_}长度最大长度为:{length}',
    email: '不是一个有效的邮箱'
  },
  fields: {
    code: {
      required: '请输入{_field_}!!!!'
    }
  }
})
